package com.google.shop.product.service.impl.product;

import com.google.shop.product.entity.product.ProductSku;
import com.google.shop.product.entity.product.ProductSkuSaleAttrName;
import com.google.shop.product.entity.product.ProductSpu;
import com.google.shop.product.entity.product.ProductSpuSpecs;
import com.google.shop.product.repository.product.ProductSkuRepository;
import com.google.shop.product.repository.product.ProductSkuSaleAttrNameRepository;
import com.google.shop.product.repository.product.ProductSkuSaleAttrValueRepository;
import com.google.shop.product.repository.product.ProductSpuDetailImagesRepository;
import com.google.shop.product.repository.product.ProductSpuRepository;
import com.google.shop.product.repository.product.ProductSpuSpecsRepository;
import com.google.shop.product.repository.product.ProductSpuSwipeImagesRepository;
import com.google.shop.product.service.product.ItemService;
import com.google.shop.product.vo.product.itemvo.DefaultSkuVO;
import com.google.shop.product.vo.product.itemvo.ItemHomePageSpuVO;
import com.google.shop.product.vo.product.itemvo.ItemVO;
import com.google.shop.product.vo.product.itemvo.SaleAttrVO;
import com.google.shop.product.vo.product.itemvo.SaleAttrValueVO;
import com.google.shop.product.vo.product.itemvo.SkuVO;
import com.google.shop.product.vo.product.itemvo.SpuDetailImageVO;
import com.google.shop.product.vo.product.itemvo.SpuVO;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/service/impl/product/ItemImpl.class */
public class ItemImpl implements ItemService {
    @Autowired
    ProductSkuRepository skuRepository;
    @Autowired
    ProductSkuSaleAttrNameRepository skuSaleAttrNameRepository;
    @Autowired
    ProductSkuSaleAttrValueRepository skuSaleAttrValueRepository;
    @Autowired
    ProductSpuRepository spuRepository;
    @Autowired
    ProductSpuDetailImagesRepository spuDetailImagesRepository;
    @Autowired
    ProductSpuSwipeImagesRepository spuSwipeImagesRepository;
    @Autowired
    ProductSpuSpecsRepository spuSpecsRepository;

    @Override // com.google.shop.product.service.product.ItemService
    public ItemVO findItemVO(Integer spuId) {
        ItemVO itemVO = new ItemVO();
        SpuVO spuVO = new SpuVO();
        List<SaleAttrVO> saleAttrVOList = new ArrayList<>();
        List<SkuVO> skuVOList = new ArrayList<>();
        List<ProductSku> skuList = this.skuRepository.findBySpuId(spuId);
        for (ProductSku sku : skuList) {
            SkuVO skuVO = new SkuVO();
            BeanUtils.copyProperties(sku, skuVO);
            skuVOList.add(skuVO);
        }
        for (ProductSkuSaleAttrName productSkuSaleAttrName : this.skuSaleAttrNameRepository.findBySpuId(spuId)) {
            SaleAttrVO saleAttrVO = new SaleAttrVO();
            BeanUtils.copyProperties(productSkuSaleAttrName, saleAttrVO);
            saleAttrVO.setSaleAttrValueVO((List) this.skuSaleAttrValueRepository.findBySpuIdAndSaleAttrNameId(productSkuSaleAttrName.getSpuId(), productSkuSaleAttrName.getSaleAttrNameId()).stream().map(e -> {
                return new SaleAttrValueVO(e.getSaleAttrValueId() + "", e.getSkuSaleAttrValue(), e.getSkuFirstLineSaleAttrValueImage());
            }).collect(Collectors.toList()));
            saleAttrVOList.add(saleAttrVO);
        }
        ProductSpu spu = this.spuRepository.findBySpuId(spuId);
        spuVO.setIsSaleAttr(Boolean.valueOf(spu.getIsSaleAttr().intValue() != 0));
        spuVO.setSpuDefaultPrice(spu.getSpuDefaultPrice() + "");
        spuVO.setSpuDefaultStock(spu.getSpuDefaultStock());
        itemVO.setSpuVO(spuVO);
        HashMap<String, String> spuDefaultImageMap = new HashMap<>();
        spuDefaultImageMap.put("picture", spu.getSpuDefaultImage());
        itemVO.setSpuDefaultImage(spuDefaultImageMap);
        spuVO.setSkuVO(skuVOList);
        spuVO.setSaleAttrVO(saleAttrVOList);
        ItemHomePageSpuVO itemHomePageSpuVO = new ItemHomePageSpuVO();
        BeanUtils.copyProperties(spu, itemHomePageSpuVO);
        Object[] spuSwipeImages = this.spuSwipeImagesRepository.findBySpuId(spuId).stream().map(e -> {
            return new String(e.getSpuSwipeImage());
        }).toArray();
        List<SpuDetailImageVO> spuDetailImageVOList = (List) this.spuDetailImagesRepository.findBySpuId(spuId).stream().map(e -> {
            return new SpuDetailImageVO(e.getSpuDetailImage());
        }).collect(Collectors.toList());
        List<ProductSpuSpecs> spuSpecsList = this.spuSpecsRepository.findBySpuId(spuId);
        itemVO.setItemHomePageSpuVO(itemHomePageSpuVO);
        itemVO.setSpuSwipeImages(spuSwipeImages);
        itemVO.setSpuSpecsList(spuSpecsList);
        itemVO.setSpuDetailImageList(spuDetailImageVOList);
        DefaultSkuVO defaultSkuVO = new DefaultSkuVO();
        if (skuList.size() != 0) {
            BeanUtils.copyProperties(skuList.get(0), defaultSkuVO);
        }
        itemVO.setDefaultSkuVO(defaultSkuVO);
        return itemVO;
    }
}
